package com.chenglu.android.payment.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chenglu.android.R;
import com.chenglu.android.common.utils.BigDecimalUtil;
import com.chenglu.android.common.utils.LogUtils;
import com.chenglu.android.common.utils.Utils;
import com.chenglu.android.couponcenter.CouponUtils;
import com.chenglu.android.payment.bean.CouponListBean;


import java.util.List;

/**
 * @author: lyj
 * @Created: by Copyright 2023 6 Guangzhou Hongma Technology Co., Ltd. All rights reserved.
 * @Description：
 */
public class OrderCouponAdapter extends BaseQuickAdapter<CouponListBean.Data, BaseViewHolder> {

     Context mContext;
    public OrderCouponAdapter(Context context, int layoutResId, @Nullable List<CouponListBean.Data> data) {
        super(layoutResId, data);
        this.mContext = context;
    }
      boolean isShow = true;
    @Override
    protected void convert(@NonNull BaseViewHolder helper, CouponListBean.Data item) {

        if(item==null){
            return;
        }
        helper.setText(R.id.tv_coupon_name,item.getCouponName());

        helper.setText(R.id.tv_tag_name,item.getShopsName()); //店铺名称


        helper.setText(R.id.tv_coupon_time, item.getReceiveTime()); //领取时间

        helper.setText(R.id.tv_date_limit, item.getUseStartTime()+"-"+item.getUseEndTime()); //时间限制
//         CheckBox checkBox =  helper.getView(R.id.cb_coupou_item);
         ImageView checkBox =  helper.getView(R.id.cb_coupou_item);


        if(item.getMinMoney()==0.0){
            helper.setText(R.id.tv_coupon_money, "无门槛可用");
        }else {
            helper.setText(R.id.tv_coupon_money, "满" + Utils.doubleTrans2(item.getMinMoney()) + "可用");
        }

        helper.setText(R.id.tv_price, Utils.doubleTrans2(item.getCouponAmount()) + "");
        //折扣
        String mul = BigDecimalUtil.mul(item.getCouponPercentage(), "10");
        helper.setText(R.id.tv_discount, Utils.formatZeroNumber(mul));

        //满减
        LinearLayout lldiscount = helper.getView(R.id.ll_discount);
        LinearLayout llprcie = helper.getView(R.id.ll_price);
        if(item.getCouponUseType()==1){
            lldiscount.setVisibility(View.GONE);
            llprcie.setVisibility(View.VISIBLE);
        }else {
            lldiscount.setVisibility(View.VISIBLE);
            llprcie.setVisibility(View.GONE);
        }

        TextView tvTag = helper.getView(R.id.tv_tag_category);

        CouponUtils.setCoupouTag(tvTag, item.getShopsTypeId());


        if(item.isTagSelect()){
            helper.setGone(R.id.ll_show_des,true);
            helper.setBackgroundRes(R.id.iv_down,R.drawable.icon_refund_up);
        }else {
            helper.setGone(R.id.ll_show_des,false);
            helper.setBackgroundRes(R.id.iv_down,R.drawable.icon_refund_down);
        }

         helper.addOnClickListener(R.id.rl_isshow);
//         helper.addOnClickListener(R.id.ll_show_des);

         if(item.getUseStatus() == 1 ){
             checkBox.setVisibility(View.VISIBLE);
             checkBox.setBackground(mContext.getResources().getDrawable(R.drawable.list_checkbox_select));
             LogUtils.d("gaodeadapter----"+ item.getUseStatus());
         }else {
            checkBox.setVisibility(View.GONE);
             LogUtils.d("gaodeadapter----"+ item.getUseStatus());
         }


    }


    //先声明一个int成员变量,若为0默认显示第一个
    private int thisPosition = 1001;

    //点击选择item
    private int thisTagPosition = 1002;

    public int getThisTagPosition() {
        return thisTagPosition;
    }

    public void setThisTagPosition(int thisTagPosition) {
        this.thisTagPosition = thisTagPosition;
    }

    //再定义一个int类型的返回值方法
    public int getthisPosition() {
        return thisPosition;
    }

    //   传入点击的位置
    public void setThisPosition(int thisPosition) {
        this.thisPosition = thisPosition;
        notifyDataSetChanged();
    }
}
